package com.ojoin.trade.t0loan_core.web.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.impl.BaseDaoImpl;
import com.ojoin.trade.t0loan_core.web.dao.TbT0LoanFinalApplicationDao;
import com.ojoin.trade.t0loan_core.web.domain.T0LoanTransTotalInfoVO;
import com.ojoin.trade.t0loan_core.web.domain.TbOutofSinglePosTranscationLog;
import com.ojoin.trade.t0loan_core.web.domain.TbT0LoanFinalApplication;
import com.ojoin.trade.t0loan_core.web.domain.TxLoanTransTotalInfoVO;

@Repository
public class TbT0LoanFinalApplicationDaoImpl extends
		BaseDaoImpl<TbT0LoanFinalApplication> implements
		TbT0LoanFinalApplicationDao {

	public SqlSession getSqlSession() {
		return this.sqlSessionTemplate;
	}

	public List<TbT0LoanFinalApplication> queryTxLoanFinalInfoByJoinUserID(
			int joinuserid) throws BusinessException {
		String mapMethodName = "queryT0LoanFinalInfoByJoinUserID";
		try {
			return getSqlSession().selectList(getSqlName(mapMethodName),
					joinuserid);
		} catch (Exception e) {
			throw new DaoException(String.format("根据joinuserid查询对象出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}

	}

	public List<TbT0LoanFinalApplication> queryTxLoanFinalInfoByJoinUserIDAndType(
			int joinuserid, String operatetype) throws BusinessException {
		String mapMethodName = "queryTxLoanFinalInfoByJoinUserID";
		try {
			HashMap<String, Object> param = new HashMap<String, Object>();
			param.put("joinuserid", joinuserid);
			param.put("operatetype", operatetype);
			
			return getSqlSession().selectList(getSqlName(mapMethodName),
					param);
		} catch (Exception e) {
			throw new DaoException(String.format("根据joinuserid查询对象出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}

	}
	
	public List<TxLoanTransTotalInfoVO> queryAllTxLoanJoinUserTransanctionTotalList(Pageable page, String operatetype) throws BusinessException {
		String mapMethodName = "queryAllTxLoanJoinUserTransanctionTotalList";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("operatetype", operatetype);
			return getSqlSession().selectList(getSqlName(mapMethodName), paramMap, this.getPageBounds(page));
		} catch (Exception e) {
			throw new DaoException(String.format("operatetype" + operatetype + "查询Tx可贷款商户列表信息出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}

	}

	public List<T0LoanTransTotalInfoVO> queryAllT0LoanJoinUserTransanctionTotalList(String shortDate, String shortTime, Pageable page) throws BusinessException {
		String mapMethodName = "queryAllT0LoanJoinUserTransanctionTotalList";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("shortDate", shortDate);
			paramMap.put("shortTime", shortTime);
			return getSqlSession().selectList(getSqlName(mapMethodName), paramMap, this.getPageBounds(page));
		} catch (Exception e) {
			throw new DaoException(String.format("根据transLastTime查询T0可贷款商户列表信息出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}

	}
	
	@Override
	public List<T0LoanTransTotalInfoVO> queryAllOutOfDayJoinUserTransanctionTotalList(
			String shortDate, String shortTime, Pageable page) throws BusinessException {
		String mapMethodName = "queryAllOutOfDayJoinUserTransanctionTotalList";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("shortDate", shortDate);
			paramMap.put("shortTime", shortTime);
			return getSqlSession().selectList(getSqlName(mapMethodName),
					paramMap, this.getPageBounds(page));
		} catch (Exception e) {
			throw new DaoException(String.format("根据transLastTime查询日额度超限商户列表信息出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}

	@Override
	public List<T0LoanTransTotalInfoVO> queryAllOutofSingleJoinUserTransanctionTotalList(
			String shortDate, String shortTime, Pageable page) throws BusinessException {
		String mapMethodName = "queryAllOutofSingleJoinUserTransanctionTotalList";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("shortDate", shortDate);
			paramMap.put("shortTime", shortTime);
			return getSqlSession().selectList(getSqlName(mapMethodName),
					paramMap, this.getPageBounds(page));
		} catch (Exception e) {
			throw new DaoException(String.format("根据transLastTime查询单笔额度超限商户列表信息出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}
	
	@Override
	public List<TbOutofSinglePosTranscationLog> queryOutofSinglePosTranscationLogListByMhtno(
			String mhtno, String shortDate, String shortTime, Pageable page) throws BusinessException {
		String mapMethodName = "queryOutofSinglePosTranscationLogListByMhtno";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("mhtno", mhtno);
			paramMap.put("shortDate", shortDate);
			paramMap.put("shortTime", shortTime);
			return getSqlSession().selectList(getSqlName(mapMethodName),
					paramMap, this.getPageBounds(page));
		} catch (Exception e) {
			throw new DaoException(String.format("根据mhtno查询商户单笔额度超限交易记录列表信息出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}
}
